package com.wxzz.elearing.evaluation.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wxzz.elearing.evaluation.entity.BusinessCategoryTopic;
import com.wxzz.elearing.evaluation.entity.Topic;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 工厂体检/星级认证/能力测评关联题目 Mapper 接口
 * </p>
 *
 * @author
 * @since 2021-04-10
 */
public interface BusinessCategoryTopicMapper extends BaseMapper<BusinessCategoryTopic> {


    /**
     * 根据分组查询工厂体检/星级测试/能力测评对应的分组的测试题
     *
     * @param type
     * @param commonId
     * @param businessCategoryId
     * @return
     */
    @Select("SELECT\n" +
            "\tt.* \n" +
            "FROM\n" +
            "\t`business_category_topic` bct\n" +
            "\tJOIN topic t ON bct.topic_id = t.id \n" +
            "WHERE\n" +
            "\tbct.type = #{type} \n" +
            "\tAND bct.common_id = #{commonId} AND bct.deleted = 0\n" +
            "\tAND bct.business_category_id = #{businessCategoryId} AND t.deleted = 0")
    List<Topic> selectTopicJoinBusinessCategoryTopic(@Param("type") Integer type, @Param("commonId") Long commonId, @Param("businessCategoryId") Long businessCategoryId);

    @Select("SELECT\n" +
            "\tCOUNT( 1 ) \n" +
            "FROM\n" +
            "\t`business_category_topic` bct\n" +
            "\tJOIN topic t ON bct.topic_id = t.id \n" +
            "WHERE\n" +
            "\tbct.type = #{type} \n" +
            "\tAND bct.common_id = #{commonId} \n" +
            "\tAND bct.deleted = 0 \n" +
            "\tAND t.deleted = 0")
    Integer countTopicJoinBusinessCategoryTopic(@Param("type") Integer type, @Param("commonId") Long commonId);
}
